package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author stone
 * @date 2022/08/09 09:53
 */
@RestController
public class HelloController {

    @Autowired
    ConfigurableConversionService conversionService;

    @RequestMapping("hello")
    public BaseRespVo hello() {
        System.out.println("hello world handler");
        return BaseRespVo.ok("hello");
    }
    @RequestMapping("goodbye")
    public BaseRespVo goodbye() {
        System.out.println("byebye");
        return BaseRespVo.ok("byebye");
    }

    //localhost:8080/user/insert?username=songge&password=songge
    /*@RequestMapping("user/insert")
    //public BaseRespVo insert(String username, String password) {
    public BaseRespVo insert(User user) {
        return BaseRespVo.ok(null);
    }*/

    // user这个参数值作为user对象中的username和password
    // 请求参数名叫user、Handler方法的形参名也叫user，而形参的类型并不是String
    // 这种情况下，应该找一个什么样的Converter    → String => User
    //localhost:8080/user/insert?user=songge
    @RequestMapping("user/insert")
    public BaseRespVo insert(User user) {
        return BaseRespVo.ok(null);
    }
}
